package com.nurt.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.nurt.dao.DishDao;
import com.nurt.dao.impl.DishDaoImpl;
import com.nurt.entity.DishEntity;
import com.nurt.service.DishService;

public class DishServiceImpl implements DishService {
    private DishDao dishDao;

    public DishServiceImpl() {
        this.dishDao = new DishDaoImpl();
    }

    public DishEntity getDish(int dishId) {
        DishEntity dish = null;
        try {
            dish = dishDao.selectDish(dishId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return dish;
    }

    public List<DishEntity> getDishes() {
        List<DishEntity> dishes = null;
        try {
            dishes = dishDao.selectDishes();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return dishes;
    }

    public int addDish(DishEntity newDish) {
        try {
            int dishId = dishDao.insertDish(newDish);
            return dishId;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }

    public void updateDish(DishEntity dish) {
        try {
            dishDao.updateDish(dish);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}